package cn.wolfcode.ssm.service.impl;

import cn.wolfcode.ssm.domain.SystemDictionaryItem;
import cn.wolfcode.ssm.mapper.SystemDictionaryItemMapper;
import cn.wolfcode.ssm.qo.QueryObject;
import cn.wolfcode.ssm.service.ISystemDictionaryItemService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SystemDictionaryItemImpl implements ISystemDictionaryItemService {

    @Autowired
    private SystemDictionaryItemMapper systemDictionaryItemMapper;

    @Override
    public void deleteById(Long id) {
        if(id != null){
            systemDictionaryItemMapper.deleteByPrimaryKey(id);
        }
    }

    @Override
    public void save(SystemDictionaryItem systemDictionaryItem) {
        systemDictionaryItemMapper.insert(systemDictionaryItem);

    }

    @Override
    public SystemDictionaryItem selectById(Long id) {
        if(id != null){
            return systemDictionaryItemMapper.selectByPrimaryKey(id);
        }
        return null;
    }

    @Override
    public PageInfo<SystemDictionaryItem> query(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<SystemDictionaryItem> systemDictionaryItems = systemDictionaryItemMapper.selectForList(qo);
        return new PageInfo<>(systemDictionaryItems);
    }

    @Override
    public List<SystemDictionaryItem> ListAll() {
        return systemDictionaryItemMapper.selectAll();
    }


    @Override
    public void updateById(SystemDictionaryItem systemDictionaryItem) {
        systemDictionaryItemMapper.updateByPrimaryKey(systemDictionaryItem);
    }

    @Override
    public List<SystemDictionaryItem> selectByTypeId(Long id) {
        return systemDictionaryItemMapper.selectByTypeId(id);
    }
    @Override
    public List<SystemDictionaryItem> selectCategoryBySn(String sn) {
        return systemDictionaryItemMapper.selectCategoryBySn(sn);
    }

    @Override
    public List<SystemDictionaryItem> selectItemByParentId(Long parentId) {
        return systemDictionaryItemMapper.selectItemByParentId(parentId);
    }
}
